package com.zyhl.gmall.product.mytest.demo04;

import java.util.function.Consumer;

/**
 * 案例需求
 * String[] strArray = {"林青霞,30", "张曼玉,35", "王祖贤,33"};
 * 字符串数组中有多条信息，请按照格式：“姓名：XX,年龄：XX"的格式将信息打印出来
 * 要求：
 * 把打印姓名的动作作为第一个Consumer接口的Lambda实例
 * 把打印年龄的动作作为第二个Consumer接口的Lambda实例
 * 将两个Consumer接口按照顺序组合到一起使用
 */
public class ConsumerTest {

    public static void main(String[] args) {
        String[] array = {"张三,30","李四,20","王五,10"};

        printInfo(array,s ->
            System.out.println("姓名:"+s.split(",")[0]+","+"年龄:"+s.split(",")[1]),
                s -> System.out.printf("年龄:"+s.split(",")[1]));

    }


    private static void printInfo(String[] array,
                                  Consumer<String> consumer,
                                  Consumer<String> consumer2){

        for (String str:array) {
            consumer.andThen(consumer2).accept(str);
        }

    }

}
